package com.sise.wangzhan.client;

import com.sise.wangzhan.command.CommandHelloWorld;
import com.sise.wangzhan.command.ObservableCommandHello;
import rx.Observable;
import rx.Observer;

import java.util.Iterator;

/**
 * @Classname ObservableCommandHelloMain
 * @Description TODO
 * @Date 2020/4/22 22:18
 * @Created by wangzhan
 */
public class ObservableCommandHelloMain {
    public static void main(String[] args) {
        //使用obserber方法
        Observable<String> ho = new ObservableCommandHello("Asynchronous-hystrix").observe();
        Iterator<String> iterator = ho.toBlocking().getIterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }

        //使用toObservable方法后，命令不会马上执行
        Observable<String> ho2 = new ObservableCommandHello("Asynchronous-hystrix").toObservable();
        //进行订阅，此时会执行命令
        ho2.subscribe(new Observer<String>() {
            @Override
            public void onCompleted() {
                System.out.println("    命令执行完成");
            }

            @Override
            public void onError(Throwable throwable) {

            }

            @Override
            public void onNext(String s) {
                System.out.println("  命令执行结果："+s);
            }
        });



    }
}
